<?php
include_once 'phpexcel/PHPExcel/Reader/Excel2007.php';
include_once 'phpexcel/PHPExcel/Reader/Excel5.php';
include_once 'phpexcel/PHPExcel/Cell.php';
require_once 'D:/fbg_gd/php_demo/vendor/autoload.php';

class ReadExcel
{
    public static function read($filePath,$map=array(),$sheet=""){
        if(!file_exists($filePath)){
            die("excel 文件不存在");
        }
        $PHPReader = new PHPExcel_Reader_Excel2007();
        if (!$PHPReader->canRead($filePath)) {
            $PHPReader = new PHPExcel_Reader_Excel5();
            if (!$PHPReader->canRead($filePath)) {
                die('File Can Not Be Readed.');
            }
        }

        $phpExcel = $PHPReader->load($filePath);
        if(is_int($sheet)){
            $currentSheet = $phpExcel->getSheet($sheet);
        }else{
            $currentSheet = $phpExcel->getSheetByName($sheet);
        }
        if(empty($currentSheet)){
            die("无数据");
        }

        // 获取excel行数
        $rowCount = $currentSheet->getHighestRow();
        // 获取有多少列
        $columnCount = PHPExcel_Cell::columnIndexFromString($currentSheet->getHighestColumn());

        $titleMaps = [];
        for($rowNum=1;$rowNum<=$rowCount;$rowNum++){
            for($j=0; $j<$columnCount; $j++){
                $value = $currentSheet->getCellByColumnAndRow($j,$rowNum)->getValue();
                if($j==2){

                    //时间格式
                    $value = $currentSheet->getCell('C1')->getValue();
                    $value = $currentSheet->getCellByColumnAndRow($j,$rowNum)->getFormattedValue($value);
                    print_r($value);
                    die();
                }

                $titleMaps[$rowNum][$j] = $value;
            }
        }

        print_r($titleMaps);
        die();



        die("read");
    }
}

ReadExcel::read("D:/fbg_gd/php_demo/excle/php_excel/01simple.xlsx",array(),0);
